#include<bits/stdc++.h>
#define int long long
using namespace std;
int q,l,r,L,R,sum,num,ans;
signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("comb.in","r",stdin);
	freopen("comb.out","w",stdout);
	cin>>q;
	while(q--){
		cin>>l>>r,ans=0;
		for(int x=l;x<=r;x++){
			for(int y=l;y<=x;y++){
				ans+=((y&(x-y))==0);
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
/*
4
1 3
1 100
103 300
5010 9999

*/
